/**
 * $version:  0.1 
 * $Date: 2011-01-21 
 *
 * Copyright (C) 2010-2011 Jawa Software. All rights reserved.
 *
 */

package org.jawa.user;

import org.jawa.util.cache.CacheSizes;
import org.jawa.util.cache.Cacheable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * 用户信息 .
 */
public class User implements Cacheable {

	private static final long serialVersionUID = -8557878791634494271L;

	private static final Logger Log = LoggerFactory.getLogger(User.class);

	private Long id;
	private String username;
	private String name;
	private String email;
	private String password;

	public User() {
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getEmail() {
		return email;
	}

	public void setEmail(String email) {
		this.email = email;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}


	@Override
	public String toString() {
		return username;
	}

	@Override
	public int hashCode() {
		return username.hashCode();
	}

	@Override
	public boolean equals(Object object) {
		if (this == object) {
			return true;
		}
		if (object != null && object instanceof User) {
			return username.equals(((User) object).getUsername());
		} else {
			return false;
		}
	}
	
	public int getCachedSize() {
		int size = 0;
		size += CacheSizes.sizeOfObject(); // overhead of object
		size += CacheSizes.sizeOfLong(); // id
		size += CacheSizes.sizeOfString(username); // username
		size += CacheSizes.sizeOfString(name); // name
		size += CacheSizes.sizeOfString(email); // email
		size += CacheSizes.sizeOfString(password); // password
		return size;
	}
}